<?php
/**
* @version		$Id: mod_unread.php 6534 2007-02-08 16:19:16Z pasamio $
* @package		Joomla
* @copyright	Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
//echo "abrakada";
global $task;
define ( 'SPACERCHAR' , ' | ' );

// Include the Tooltips
JHTML::_('behavior.tooltip');//1.5b2

// Check if mainmenu is hidden
$hidemainmenu = JRequest::getVar('hidemainmenu');

// Initialize some variables
$config		=& JFactory::getConfig();
$user		=& JFactory::getUser();
$db			=& JFactory::getDBO();
$lang		=& JFactory::getLanguage();
$session	=& JFactory::getSession();

$sid	= $session->getId();

$output = array();

$showdiv = intval( $params->get( 'showdiv', 1 ) );

// Legacy Mode
if (defined('_J_LEGACY'))
{
	$output[] = '<span class="legacy-mode">'.JText::_('Legacy').': '._J_LEGACY.'</span>';
}


$database =& JFactory::getDBO();
$mosConfig_live_site =  $mainframe->getCfg('live_site');//TODO NiK :: yeah we'll change soon..'///////////////
	$database->setQuery("SELECT * FROM #__extension_icons"
						. "\n WHERE published = 1"
					    . "\n ORDER BY ordering");
	$rows = $database->loadObjectList();

	foreach ( $rows as $row )
	{
		$Line = '';
		$LineTT ='<img src=\''.$mosConfig_live_site . '/includes/' .$row->admin_menu_img.'\' />'
				. ' <strong>'.$row->name.'</strong><br />'
				. $row->admin_menu_alt;
		if ( $showdiv ) $Line .= '<div>';
//		$Line .= '<span class="editlinktip hasTip" title="Hallo" style="width:16px;">';
		$Line .= '<a href="' . $mosConfig_live_site . '/administrator/index.php?'
		 . $row->admin_menu_link . '">'
		 . '<img src="' . $mosConfig_live_site . '/includes/' . $row->admin_menu_img . '"'
		 . ' class="hasTip"'
		 . ' align="middle" border="0"'
		 . ' alt="' . $row->admin_menu_alt . '"'
		 . ' title="' .$LineTT.'"'// $row->admin_menu_alt . '"'
		 . ' /></a>';//'</span>';

		$Line .= ( $showdiv ? '</div>' : ' ' );
		$output[] = $Line;
	}//foreach

	//echo SPACERCHAR;

/*
 * External Preview
 */
if ( $params->get ( 'showexternalpreview' ) )
{
	$output[] = '<a href="'.$mainframe->getSiteURL().'" target="_blank" alt="'.JText::_('Preview').'">' .
				'<img src="../includes/js/ThemeOffice/preview.png" align="middle" border="0" alt="preview"' .
				' class="error hasTip" title="'.JText::_('ttip external preview').'"/></a> ';
}		

/**
 * Unread Messages
 */
if ( $params->get ( 'showunread' ) )
{
	$query = 'SELECT COUNT(*)'
	. ' FROM #__messages'
	. ' WHERE state = 0'
	. ' AND user_id_to = '.$user->get('id');

	$db->setQuery( $query );
	$unread = $db->loadResult();

	if (JRequest::getVar('hidemainmenu'))
	{
		$inboxLink = '<a>';
	} else
	{
		$inboxLink = '<a href="index.php?option=com_messages">';
	}

	if ($unread)
	{
		$output[] = $inboxLink
			.'<img src="images/mail.png" align="middle" border="0" alt="Mail"' .
			 ' class="hasTip" title="'
			 . JText::_('tt unread title')
			 . JText::_('tt your private messages')
			 . JText::sprintf( 'tt you have', $unread ) 
			 . '" />'
			 . $unread
			 . '</a>';
			 
//			 . JText::_('tt unread gotmailMail" />'.$unread.'</a> ';
	} else
	{
		$output[] = $inboxLink
			.'<img src="images/nomail.png" align="middle" border="0" alt="No Mail"' .
				' class="hasTip" title="'
				. JText::_('tt unread title nomail')
				. JText::_('tt your private messages')
				. JText::_('tt No new messages')
				. '" />'
				. '</a>';
	}
}//if show unread

/**
 * Logged in users
 */	
// Get the number of logged in users
$query = 'SELECT COUNT( session_id )'
. ' FROM #__session'
. ' WHERE guest <> "1"'
;
$db->setQuery($query);
$online_num = intval( $db->loadResult() );

//Print the logged in users message
$output[] = '<img src="images/users.png" align="middle" border="0"' .
			' alt="Online Users" class="hasTip"' .
			' title="'.JText::_('tt onlineusers').'" />'.
			$online_num.' ';

/**
 * Logout message
 */
$LogLev = $params->get ( 'showlogoutlevel' );
if ( $LogLev > 0 )
{

	if ($task == 'edit' || $task == 'editA' || JRequest::getVar('hidemainmenu') )
	{
	 // Print the logout message as text
	 	$output[] = '<img src="images/publish_x.png" align="middle" border="0" alt="Logout"' .
	 			' class="hasTip" title="' .
	 			JText::_('tt Logout').'" />' .
		 		JText::_('Logout');
	} else {
	// Print the logout message as link
		$tmpOutput = '<a href="index.php?option=com_login&task=logout">';
		if ( $LogLev == 1 | $LogLev == 3 )
		{
			$tmpOutput .= '<img src="images/publish_x.png"' .
						' align="middle" border="0" alt="Logout"' .
						' class="hasTip" title="' .
	 					JText::_('tt Logout').'" />';
		}
		if ( $LogLev == 2 | $LogLev == 3 )
		{
	 		$tmpOutput .= JText::_('Logout').'</a>';
		}
		$output[] = $tmpOutput;
	}//if hidemainmenu
}//if loglevel
/*
	$LogLev = $params->get ( 'showlogoutlevel' );
	if ( $LogLev > 0 )
	{
		echo '<a href="index2.php?option=logout" ' . nik_TT (_TT_LOGOUT, _TT_LOGOUT_TIT, 100) .'>';
		if ( $LogLev == 1 | $LogLev == 3 )
		{
			echo '<img src="images/publish_x.png" align="middle" border="0" />';
		}
		if ( $LogLev == 2 | $LogLev == 3 )
		{
			echo _TT_EXICONS_LOGOUT;
		}

		echo '</a>';
	}
*/


// reverse rendering order for rtl display// copied just for fun ;) - NiK.. 
if ( $lang->isRTL() ) {
	$output = array_reverse( $output );
}

// output the module
foreach ($output as $item)
{
	echo $item;
}

?>
